package com.jamaskii.dictation;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

public class GuideActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        TextView labelDeclaration=findViewById(R.id.label_declaration);
        labelDeclaration.setText(getString(R.string.declaration));
        TextView labelAuthor=findViewById(R.id.label_author);
        labelAuthor.setText(getString(R.string.author));
        setTopPadding();
    }

    public void onChoose(View view){
        switch (view.getId()){
            case R.id.label_deny:
                choose(false);
                break;
            case R.id.label_accept:
                choose(true);
                break;
        }
    }

    private void choose(boolean accept){
        Intent intent=new Intent();
        intent.putExtra("accept",accept);
        setResult(RESULT_OK,intent);
        finish();
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event){
        if(keyCode==KeyEvent.KEYCODE_BACK){
            choose(false);
            return false;
        }
        return false;
    }
    public int getStatueBarHeight(){
        int statusBarHeight = -1;
        try {
            Class<?> clazz = Class.forName("com.android.internal.R$dimen");
            Object object = clazz.newInstance();
            int height = Integer.parseInt(clazz.getField("status_bar_height")
                    .get(object).toString());
            statusBarHeight = getResources().getDimensionPixelSize(height);
            return statusBarHeight;
        } catch (Exception e) {
            return 24;
        }
    }

    private void setTopPadding(){
        ConstraintLayout layout=findViewById(R.id.padding) ;
        ViewGroup.LayoutParams layoutParams=layout.getLayoutParams();
        layoutParams.height=getStatueBarHeight();
        layout.setLayoutParams(layoutParams);
    }
}